﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";

    //收据报表链接
    var invoiceReportUrl = SysConfigReader.OrgReportLink("NewInpatientSett");
    var invoiceReportUrls = SysConfigReader.OrgReportLink("NewInpatientSetts");
    var reportUrl = Newtouch.Core.Common.Utils.ConfigurationHelper.GetAppConfigValue("ReportUrl");
    var reportSystemCode= Newtouch.Core.Common.Utils.ConfigurationHelper.GetAppConfigValue("ReportSystemCode");
    var curOpr = Newtouch.Common.Operator.OperatorProvider.GetCurrent();
}

<form>
    <div class="panel panel-default">
        <div class="panel-heading navb-bg">
            筛选条件
        </div>
        <table class="form">
            <tr>
                <th class="formTitle">关键字：</th>
                <td class="formValue">
                    <input id="txt_keyword" type="text" class="form-control form-an" placeholder="姓名/病历号/住院号">
                </td>
                <th class="formTitle">发票号：</th>
                <td class="formValue">
                    <input type="text" class="form-control" id="searchFPH" name="searchFPH" />
                </td>
                <th class="formTitle">结算日期：</th>
                <td class="formValue" colspan="2">
                    <input id="jsksrq" type="text" class="form-control input-wdatepicker" style="width:42%; float:left;" value="@DateTime.Now.ToString("yyyy-MM-01")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" />
                    <span style="margin-left:1%;float:left">—</span>
                    <input id="jsjsrq" type="text" class="form-control input-wdatepicker" style="width:43%; float:left;margin-left:1%;" value="@DateTime.Now.ToString("yyyy-MM-dd")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" />
                </td>
                <td class="formValue">
                    <input type="button" id="btn_search" class="btn btn-primary" style="width:36%;margin-left: 10%;" value="查询" />
                </td>
                <th class="formTitle"></th>
                <td class="formValue"></td>
            </tr>
        </table>
    </div>
    <div class="gridPanel">
        <table id="gridList"></table>
        <div id="gridPager"></div>
    </div>
    <div style="background-color: #fff; margin-top:5px;">
        <table id="gridJSMXList"></table>
    </div>
    <div style="background-color: #fff; margin-top:5px; ">
        <input type="button" id="HZQD" class="btn btn-primary" style="width:60px;float:right;margin-right:10px;" value="汇总清单" />
        <input type="button" id="btn_cyjsd_print" class="btn btn-primary" style="width:60px;float:right;margin-right:10px;" value="医保结算单" />
    </div>
</form>

<script>
    var jsnms = "";
    var zyhs = "";
    var reportServerHOST = '@(ViewBag.ReportServerHOST)';
    var orgId = '@(ViewBag.OrgId)';

    $(function () {
        gridList();

        //回车事件
        $('#txt_keyword').keydownEnterEvent(function () {
            $('#btn_search').trigger('click');
        })
    })

    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "@Url.Action("GetPaginationSettlementList")",
            height: 150,
            postData: getpostData(),
            colModel: [
                { label: 'jsnm', name: 'jsnm', key: true, hidden: true },
                {
                    label: "操作", name: "", width: 100, align: 'left',
                    formatter: function (cellvalue, options, rowobject) {
                        var str = "";
                        // if (!!rowobject.fph) {
                        str += '&nbsp;<a class="btn btn-default" title="打印发票" style="width: 80%;" onclick="printFp(\'' + rowobject.jsnm + '\')">打印发票</a>';
                        //}
                        //str += '&nbsp;<a class="btn btn-default" title="发票补打" style="width: 26%;" onclick="supplementprintFp(\'' + rowobject.jsnm + '\')">发票补打</a>';
                        return str;
                    }
                },
                { label: '住院号', name: 'zyh', width: 40, align: 'left' },
                { label: '姓名', name: 'xm', width: 60, align: 'left' },
                { label: '性别', name: 'xb', width: 30, align: 'left' },
                { label: '身份证', name: 'zjh', width: 115, align: 'left' },
                { label: '出生日期', name: 'csrq', width: 60, align: 'left' },
                { label: '新生儿', name: 'isxsr', width: 40, align: 'left' },
                { label: '民族', name: 'mz', width: 25, align: 'left' },
                { label: '主治医生', name: 'zzys', width: 50, align: 'left' },
                { label: '归转', name: 'gz', width: 25, align: 'left' },
                { label: '离院方式', name: 'lyfs', width: 50, align: 'left' },
                { label: '出院诊断', name: 'cyzd', width: 50, align: 'left' },
                { label: '家庭地址', name: 'jtdz', width: 50, align: 'left' },
                { label: '费用性质', name: 'brxzmc', width: 50, align: 'left' },
                { label: '入院日期', name: 'ryrq', width: 60, align: 'left', formatter: "date", formatoptions: { srcformat: 'Y-m-d', newformat: 'Y-m-d' } },
                { label: '出院日期', name: 'cyrq', width: 60, align: 'left', formatter: "date", formatoptions: { srcformat: 'Y-m-d', newformat: 'Y-m-d' } },
                { label: '发票号', name: 'fph', width: 60, align: 'left' },
                { label: '总金额', name: 'zje', width: 80, align: 'left', formatter: 'number', formatoptions: { thousandsSeparator: ",", decimalPlaces: 2 } },
                { label: '现金支付', name: 'xjzf', width: 80, align: 'left', formatter: 'number', formatoptions: { thousandsSeparator: ",", decimalPlaces: 2 } },
                { label: '结算人员', name: 'CreatorCode', width: 60, align: 'left' },
                { label: '结算时间', name: 'CreateTime', width: 120, align: 'left', formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s' } },
                
            ],
            pager: "#gridPager",
            sortname: 'CreateTime desc',
            viewrecords: true,
            onSelectRow_page: function (rowid) {
                btn_selectrow();
            },
            gridComplete: function (gridJszbList) {
                jszbList = null;
                if (gridJszbList && gridJszbList.rows) {
                    jszbList = gridJszbList.rows;
                }
            }
        });

        $("#btn_search").click(function () {
            $('#gridJSMXList').jqGrid("clearGridData");//先清空明细
            $gridList.jqGrid('setGridParam', {
                postData: getpostData(),
                page: 1,
            }).trigger('reloadGrid');
        });
    }

    var jszbList = null;

    function getpostData() {
        return {
            keyword: $("#txt_keyword").val(), fph: $('#searchFPH').val(), jsksrq: $("#jsksrq").val(), jsjsrq: $("#jsjsrq").val()
        };
    }

    //单击事件
    function btn_selectrow() {
        jsnms = $("#gridList").jqGridRowValue().jsnm;
        zyhs = $("#gridList").jqGridRowValue().zyh;
        console.info("jsnms:" + jsnms);
        console.info("zyh:" + zyhs);

        //每次单击，先清空上一条明细 和合计
        $('#gridJSMXList').jqGrid("clearGridData");
        $.najax({
            type: "POST",
            url: "/HospitalizationManage/Settlement/GetSettlementDetails",
            data: { jsnm: $("#gridList").jqGridRowValue().jsnm },
            dataType: "json",
            success: function (ajaxresp) {
                $('#gridJSMXList').newtouchLocalDataGrid(null, ajaxresp);
            }
        });
    }

    //结算明细 jGrid声明
    $('#gridJSMXList').newtouchLocalDataGrid({
        height: $(window).height() - 400,
        caption: "结算明细",
        unwritten: false,
        colModel: [
            { label: '分类代码', name: 'dlcode', hidden: true },
            { label: '费用大类', name: 'dlmc', width: 80, align: 'left' },
            {
                label: '金额', name: 'je', width: 80, align: 'left', formatter: function (cellvalue) {
                    return cellvalue ? cellvalue.toFixed(2) : "0.00";
                }
            },
        ],
        viewrecords: true,
        ondblClickRow: function (row) {
            btn_clickrow();
        }
    });
    //双击弹出费用明细
    function btn_clickrow() {
        var dlcode = $("#gridJSMXList").jqGridRowValue().dlcode;
        $.modalOpen({
            id: "GetSettlementItems",
            title: "明细项目查询",
            url: "/HospitalizationManage/Settlement/GetSettlementItems?dlCode=" + dlcode + "&zyh=" + zyhs + "&jsnms=" + jsnms,
            width: "900px",
            height: "600px",
            btn: null,
            callBack: function (iframeId) {
            }
        });
    }
    
    //打印汇总清单

    var curUserCode = '@(ViewBag.CurUserCode)';
    //打印明细
    var srcUrl = "";
    $("#HZQD").click(function () {
        
        var srcUrl = '@reportUrl' + "?tempCode=96" + "&hospitalCode=" + orgId + "&zyh=" + zyhs + "&jsnm=" + jsnms + "&systemCode=" + '@reportSystemCode';

        //var urldy = "/ReportServer/Pages/ReportViewer.aspx?%2fHIS.Report.1%2f汇总清单统计表&rs:Command=Render&rc:Stylesheet=MyStyleSheet&orgId=" + orgId + "&CZY=" + curUserCode + "&zyh=" + zyhs + "&jsnm=" + jsnms;
        //if (urldy.StartWith('/')) {
        //    urldy = urldy.substr(1);
        //}
        //srcUrl= urldy;
        //srcUrl = reportServerHOST + srcUrl;
        window.open(srcUrl);


    })    
        
    //医保出院结算单
    $("#btn_cyjsd_print").click(function () {
        var zyh = $("#gridList").jqGridRowValue().zyh;
        if (!!zyh) {
            var jsdurl = reportServerHOST + "/ReportServer/Pages/ReportViewer.aspx?%2fHIS.Report.1%2fChongqing医保出院结算单&rs:Command=Render&rc:Stylesheet=MyStyleSheet&orgId=" + orgId + "&zyh=" + zyh;
            window.open(jsdurl);
        }
        else {
            $.modalAlert("请选择一条结算记录","warning");
        }
    });








</script>
<script type="text/javascript">
    function printFp(jsnm, ver) {
        var zyh = $("#gridList").jqGridRowValue().zyh;
        var orgId = '@curOpr.OrganizeId';
        var uri = '@Html.Raw(reportUrl)' + "?tempCode=05" + "&jsnm=" + jsnm + "&orgId=" + orgId + "&zyh=" + zyh + "&systemCode=" + '@reportSystemCode';
        window.open(uri, "_blank", "height=500, width=1195,top=100, left=50, toolbar =no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no");
    }

    //发票补打
    function supplementprintFp(jsnm) {
        tempJSNM = jsnm;
        $.modalOpen({
            id: "InvoiceNoPanel",
            title: "选发票号",
            url: "/OutpatientManage/OutpatientReg/ChooseInvoice",
            width: "300px",
            height: "200px",
            callBack: function (iframeId) {
                top.frames[iframeId].checkFPH();//窗口点确定的回调函数
            }
        });

    }

    var tempJSNM;
    //补打，选择了新的发票号
    function chooseFPHSuccessCallback(fph) {
        //更新结算记录的发票号为新发票号
        $.najax({
            type: "POST",
            url: "/HospitalizationManage/Settlement/UpdateSettInvoiceNo",
            data: { jsnm: tempJSNM, fph: fph-1 },
            dataType: "json",
            success: function (data) {
                //打印
                printFp(tempJSNM,"N");
            }
        });
    }




</script>
